/****************************** (C) COPYRIGHT 2016 RSEStudio ****************************
* File Name          : 
* Author             : RSES_Liyang
* Version            : V1.0.0
* Date               : 00-May-18
* Description        : 
*****************************************************************************************/

#ifndef __BUTTON_H__
#define __BUTTON_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ----------------------------------------------------------------------------*/
/* Exported define ---------------------------------------------------------------------*/
#define BUTTON_MAX_NBR					6
#define BUTTON_MAX_NAME_LENGTH			16

#define BUTTON_DEBOUNCE_TIME 	  		2   	/* �������� */
#define BUTTON_LONG_TIME 	      		100		/* ������������ */
#define BUTTON_DOUBLE_TIME      		35 		/* ˫����������� */
#define BUTTON_LONG_CYCLE       		10 //100	  	/* ������������������� */

#define BUTTON_CTL_ENABLE				0x01
#define BUTTON_CTL_CANCEL_EVENT			0x02
#define BUTTON_CTL_GET_LEVEL			0x03
#define BUTTON_CTL_TRIGGER				0x04

#define BUTTON_EVENT_NONE						0
#define BUTTON_EVENT_PRESS						1
#define BUTTON_EVENT_RELEASE					2
#define BUTTON_EVENT_CLICK						3
#define BUTTON_EVENT_ONLY_CLICK					4
#define BUTTON_EVENT_DOUBLE						5
#define BUTTON_EVENT_LONG						6
#define BUTTON_EVENT_LONG_REPEAT				7
#define BUTTON_EVENT_LONG_FREE					8

/* Exported macro ----------------------------------------------------------------------*/
/* Exported types ----------------------------------------------------------------------*/
//typedef enum _btn_event
//{
//	event_none = 0,			/* ���¼� */
//	event_press,			/* ���°����������� */
//	event_release,			/* �ɿ������������� */
//	event_click,			/* ���µ��𴥷�(˫��Ҳ�ᴥ��) */
//	event_only_click,		/* ���µ��𴥷�(�ȴ�˫����ʱ�Ŵ���) */
//	event_double,			/* ˫������ */
//	event_long,				/* �������� */
//	event_long_repeat,		/* �����ظ����� */
//	event_long_free,		/* �����ͷŴ��� */
//}btn_event;

typedef struct _btn btn_t;

typedef void (*cb_button)(btn_t *btn,uint8_t event);   /* ���������ص���������Ҫ�û�ʵ�� */
// Example
//void cb_(btn_t *btn,btn_event event)
//{
//	switch(event)
//	{
//		case event_none:break;
//		case event_press:break;
//		case event_release:break;
//		case event_click:break;
//		case event_only_click:break;
//		case event_double:break;
//		case event_long:break;
//		case event_long_repeat:break;
//		case event_long_free:break;
//	}
//}

struct _btn
{
	uint8_t (*read_button_level)(void); 	/* ��ȡ������ƽ����,���ط���ֵ��ʾ�������� */
	cb_button callback_func;
	uint16_t control_flag;
	uint8_t state;	  						/* ����״̬�� */
	uint8_t level;    						/* ������һ��ƽ */
	uint8_t change_flag;					/* ���������л���־ */
	
	uint8_t debounce_timer;					/* ����ʱ���ʱ�� */
	uint16_t double_timer;					/* ������˫���ȴ�ʱ���ʱ�� */
	uint16_t long_timer;		  			/* �������³���ʱ���ʱ�� */
	uint16_t long_cycle_timer;		  		/* �������������������ڶ�ʱ�� */
	uint8_t name[BUTTON_MAX_NAME_LENGTH];	/* ������ */	
};

/* Exported constants ------------------------------------------------------------------*/
/* Exported functions ----------------------------------------------------------------- */
int btn_init(btn_t *btn, uint8_t(*read_btn_level)(void),cb_button cb);                                                   
void btn_process(void);                 
int btn_control(btn_t *btn,uint16_t cmd,void *params);   
                   
#ifdef __cplusplus
}
#endif

#endif
/********************************(C)COPYRIGHT 2016 RSEStudio ****************************/
/*****************************************END OF FILE************************************/

